home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / gprim / sphere / sphereload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-11  |  1.1 KB  |  59 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "geom.h"
  4. #include "geomclass.h"
  5. #include "transform.h"
  6. #include "sphereP.h"
  7.  
  8. Sphere *SphereFLoad(file, fname) 
  9.      FILE *file;
  10.      char *fname;
  11. {
  12.   int ch;
  13.   HPoint3 center;
  14.   float radius;
  15.   Geom *sphere;
  16.   int space;
  17.   int i;
  18.  
  19.   if (file == NULL) return NULL;
  20.  
  21.   space = TM_EUCLIDEAN;
  22.  
  23.   (void) fnextc(file, 0);     /* Skip white space and comments */
  24.   
  25.  
  26.   i = fgetc(file);
  27.   if (i == 'E') {
  28.     space = TM_EUCLIDEAN;
  29.     if (fexpectstr(file, "SPHERE")) return NULL;
  30.   }
  31.   else if (i == 'H') {
  32.     space = TM_HYPERBOLIC;
  33.     if (fexpectstr(file, "SPHERE")) return NULL;
  34.   }
  35.   else if (i == 'S') {
  36.     i = fgetc(file);
  37.     if (i == 'S') {
  38.       space = TM_SPHERICAL;
  39.       i = fgetc(file);
  40.     }
  41.     if (i != 'P' || fexpectstr(file, "HERE")) return NULL;
  42.   }
  43.   else return NULL;
  44.   
  45.   if ( fgetnf(file, 1, &radius, 0) != 1 ) {
  46.     return NULL;
  47.   }
  48.  
  49.   if ( fgetnf(file, 3, ¢er.x, 0) != 3 ) {
  50.     return NULL;
  51.   }
  52.   center.w = 1.0;
  53.  
  54.   sphere = GeomCreate("sphere", CR_RADIUS, (double)radius, 
  55.               CR_CENTER, ¢er, CR_SPACE, space, CR_END);
  56.  
  57.   return (Sphere *)sphere;
  58. }
  59.